module Seiso::ImportMaster::Validators
  # Author:: Willie Wheeler (mailto:wwheeler@expedia.com)
  # Copyright:: Copyright (c) 2014-2016 Expedia, Inc.
  # License:: Apache 2.0
  class ServiceValidator < BaseValidator

    def initialize
      @log = Seiso::ImportMaster::Util::Logger.new "ServiceValidator"
    end

    def validate(doc)
#      @log.info "Validating services"
      validate_services doc
    end

    private

    def validate_services(doc)
      services = doc['items']

      if services.nil?
        error 'Service document must contain an items field containing the services.'
      end

      services.each { |s| validate_service s }
    end

    def validate_service(s)
      key = s['key']
      error 'Service must have a key' if key.nil?
      name = s['name']
      error 'Service must have a name' if name.nil?

      # This isn't required!
#      type = s['type']
#      error 'Service must have a type' if type.nil?
    end
  end
end
